#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QScrollBar>
#include <QMainWindow>
#include <QHBoxLayout>
#include <QTextEdit>
#include <QWebEngineView>
#include <QSplitter>
#include <QAction>
#include "document.h"
#include "Parser.h"
#include "findandreplace.h"
#include "replace.h"
#include "highlight.h"
#include "color.h"
#include <QMessageBox>


class QLineEdit;
class QPushButton;
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT
protected:
    void dragEnterEvent(QDragEnterEvent *e);

    void dropEvent(QDropEvent *e);

public:
    void closeEvent(QCloseEvent *e) override{
        if(isModified()){
            if (isModified()) {
                QMessageBox::StandardButton button = QMessageBox::question(this, windowTitle(), tr("😲你有未保存的修改，要丢弃吗？"));
                if (button != QMessageBox::Yes)
                    e->ignore();
            }
        }
    }
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    bool isModified();
    void fileOpen(const QString& path);
    void setOptions(const string &cssPath, const string &highlightCommand, bool codeOpen,const string& name);
    void upDateOptions();
public slots:
void Parse();
void sendText();
void newFile();
void openFile();
void saveFile();
void saveAs();
void exit();
void setFont();
void configCss();
void configHlCommand();
void setCode();
void setName();
void toHTML();
void toPDF();
void highLightLine();
void setBackgroundImag();
void refreshHigh();
void findPre();
void findNext();
void showFind();
void showReplace();

signals:
void textChanged();


private:
Color* c;
Replace* replace;
FindAndReplace* find;
QDialog* findDlg;
QLineEdit* findLineEdit;
QPushButton *PreBtn;
QPushButton *NextBtn;
QString imgPath = "";
string html = "";
highlight* high;
QString filepath;
QString fileName = "";
Ui::MainWindow *ui;
Parser* parse;
QString resPath = "";
QString highlightCommand = "hljs.initHighlightingOnLoad();";
QString name = "我是谁?";
bool isCode = true;
};
#endif // MAINWINDOW_H
